package com.algorithms.linkedlists;

import com.algorithms.utils.AlgorithmException;

/**
 * this LinkedQueue bases on double-end linked list<br>
 * pop: pop at the beginning of the list<br>
 * push: at the last of the list<br>
 * 
 * @author minhld
 *
 * @param <T>
 */
public class LinkedQueue<T> {
	private DoubleEndLinkedList<T> linkedData;
	
	public LinkedQueue() {
		linkedData = new DoubleEndLinkedList<T>();
	}
	
	public T pop() throws AlgorithmException {
		if (isEmpty()){
			throw new AlgorithmException("queue is empty.");
		}else{
			Link<T> first = this.linkedData.deleteFirst();
			return first.getContent();
		}
	}

	public void push(T value) {
		this.linkedData.insertLast(value);
	}

	public T peak() {
		if (isEmpty()){
			return null;
		}
		return this.linkedData.getFirst().getContent();
	}

	public boolean isEmpty() {
		return this.linkedData.isEmpty();
	}
	
}
